package com.example.demo.Entity;

/**
 * 储存在主服务器中的块信息
 *
 * @author xyt
 */
public class ChunkInfo {
  private StringBuffer hash;        //块哈希值
  private Chunk chunk;              //块基本信息
  private String serverName;        //块所在服务器名称
  private String[] copyServerName;  //其他备份所在服务器名称

  public ChunkInfo(Chunk chunk,String hash){
    this.chunk = chunk;
    this.hash = new StringBuffer();
    this.hash.append(hash);
    this.copyServerName = new String[2];
  }

  public void removeCopyServerId(String serverName){
    if(copyServerName[0].equals(serverName)){
      copyServerName[0] = copyServerName[1];
    }
    copyServerName[1] = null;//0代表已未在任何服务器安置该副本
  }

  /**
   * getter & setter
   */
  public void setFirstCopyServerName(String serverName){
    this.copyServerName[0] = serverName;
  }

  public void setSecondCopyServerName(String serverName){
    this.copyServerName[1] = serverName;
  }

  public String getFirstCopyServerName(){
    return this.copyServerName[0];
  }

  public String getSecondCopyServerName(){
    return this.copyServerName[1];
  }

  public void removeSecondCopyServer(){
    this.copyServerName[1] = null;
  }

  public String getServerName() {
    return serverName;
  }

  public void setServerName(String serverName) {
    this.serverName = serverName;
  }

  public StringBuffer getHash() {
    return hash;
  }

  public void setHash(StringBuffer hash) {
    this.hash = hash;
  }

  public Chunk getChunk() {
    return chunk;
  }

  public void setChunk(Chunk chunk) {
    this.chunk = chunk;
  }

}
